import sgmllib

class Webkit_Parser(sgmllib.SGMLParser):
    "A simple parser class."
    next_link = False
    mac_trunk_extension = ""

    def parse(self, s):
        "Parse the given string 's'."
        self.feed(s)
        self.close()

    def __init__(self, version_name, verbose=0):
        "Initialise an object, passing 'verbose' to the superclass."

        sgmllib.SGMLParser.__init__(self, verbose)
        self.version_name = version_name

    def start_a(self, attributes):
        "Process a hyperlink and its 'attributes'."
        
        if self.next_link == True:
            for name, value in attributes:
                if name == "href":
                    #self.hyperlinks.append(value)
                    self.mac_trunk_extension = value
                    self.next_link = False

    def handle_data(self, data):
        """Check to see if header preceding correct link has been found"""
        
        if data == self.version_name:
            self.next_link = True


    def get_hyperlinks(self):
        "Return the list of hyperlinks."

        #return self.hyperlinks
        return self.mac_trunk_extension
